/*
 * jquery.errorSummary File
 *
 * @link http://riedel-st.de
 * @author Stefan Riedel <sr@riedel-st.de>
 */
;
(function($) {
    $.extend($.fn, {
        renderTable: function(obj, options) {
            if(typeof(obj)!='object') return false;
            var defaults = {
                tableBorder:0,
                tableCellspacing:2,
                tableCellpadding:0,
                tableClass:'ui-widget-content ui-corner-all',
                theadClass:'ui-widget-header',
                trClassPrefix:'state-default',
                idField: 'id'
            };
            var options = $.extend(defaults, options);
            var heads = [];
            return this.each(function(){
                table = '<table border="'+options.tableBorder+'" cellspacing="'+options.tableCellspacing+'" cellpadding="'+options.tableCellpadding+'" class="'+options.tableClass+'">\n';
                table += '<thead class="'+options.theadClass+'">\n<tr>\n';
                $.each(obj.heads, function(name, value){
                    heads = heads.concat([name]);
                    table += '<th>' + value + '</th>\n';
                });
                table += '</tr>\n</thead>\n';
                $.each(obj.result, function(i, data){
                    table += '<tr class="'+options.trClassPrefix+(i%2)+'">\n';
                    $.each(heads, function(i, resultField){
                        table += '<td>' + data[resultField] + '</td>\n';
                    });
                    table += '</tr>\n';
                });
                table += '</table>\n';
                $(this).html(table);
            });
        }
    });
})(jQuery);